package test.test;

public class MyNodeList<E> {
    private class ListNode<E> {
    Object val;
    ListNode next = null;
    ListNode(Object x) { val = x; }
    }
    private ListNode firstNode = null;
    private ListNode nowNode = null;
    public void addNode(E node){
        if (firstNode==null) {
            firstNode = new ListNode(node);
            nowNode = firstNode;
        }
        else {
            ListNode a = new ListNode(node);
            nowNode.next = a;
            nowNode = nowNode.next;
        }

    }


    @Override
    public String toString() {
        String s = "";
        while (firstNode.next!=null){
            s=s+firstNode.val.toString();
            s=s+"→";
            firstNode = firstNode.next;
        }
            return s;
    }



    public void deleteNode(ListNode node) {
        ListNode pre = null;
        while(node.next != null) {
            node.val = node.next.val;
            pre = node;
            node = node.next;
        }
        pre.next = null;
    }
}
